package com.exmaple.excel.base64;

import java.io.File;
import java.io.RandomAccessFile;

/**
 * @author Create By Liuqz
 * @date 2019/3/17 22:21
 */
public class base64Util {

    /**
     * base64转成图片  解决过来的
     * @param str
     * @param picPath
     */
    public static void getPicFormatBASE64(String str, String picPath) {
        try {
            //先创建文件目录,否则保存文件报错
            String realPath = picPath.substring(0, picPath.lastIndexOf("/"));
            File file = new File(realPath);
            if (!file.exists()) {
                file.mkdirs();
            }
            byte[] result = new sun.misc.BASE64Decoder().decodeBuffer(str
                    .trim());
            RandomAccessFile inOut = new RandomAccessFile(picPath, "rw"); // r,rw,rws,rwd
            inOut.write(result);
            inOut.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
